import cv2
import face_recognition
from face_recognition.api import face_encodings
import numpy as np
# image = cv2.imread("2.jpg")
# # print(image.shape)
# scale_percent = 10
# width = int(image.shape[1] * scale_percent / 100)
# height = int(image.shape[0] * scale_percent / 100)
# dim = (width, height)
# resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)
# cv2.imshow("hello test", resized)
# cv2.imwrite("resized.jpg", resized)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
# image = face_recognition.load_image_file("2.jpg")
# face_locations = face_recognition.face_locations(image)
# print(face_locations)

cap = cv2.VideoCapture("0.mp4")
process_this_frame = True
i = 0
while True:
    print(i)
    ret, frame = cap.read()
    # cv2.imshow("capture", frame)
    if ret:
        img = frame
        grey = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        small_frame = cv2.resize(frame, (0,0), fx=0.25, fy=0.25)
        rgb_small_frame = small_frame[:,:,::-1]
        if process_this_frame:
            face_locations = face_recognition.face_locations(rgb_small_frame)
            # face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
            # face_names = []
            # for face_encoding in face_encodings:
            #     matches = face_recognition
            if len(face_locations) > 0:
                print("检测到人脸")
                print(face_locations)
        i += 1
    else:
        break

